package com.yjx.config;

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.omath.OfficeMath;

import java.util.HashMap;

public class SetWord {
    public static void main(String[] args){
        //新建Word示例，添加一个section
        Document doc = new Document();
        Section section = doc.addSection();

        //添加段落1和段落2,添加Latex数学公式
        Paragraph paragraph1 = section.addParagraph();
        OfficeMath officeMath1 = new OfficeMath(doc);
        paragraph1.getItems().add(officeMath1);

        HashMap<String, String> map = new HashMap<>();
        map.put("β","1.3");
        map.put("T","185");
        map.put("D","310");
        map.put("d","175");
        map.put("e","4834 N");
        map.put("Z","2");
        map.put("μ","0.2");
        String a = "{F}=\\frac{3000×{\\beta }×{T}×\\left({D}+{d}\\right)}{{\\mu }×{Z}×\\left({{D}}^{2}+{D}×{d}+{{d}}^{2}\\right)}={ }{e}";
        for (int i = 0; i < map.size(); i++) {
            a.replaceAll(a,map.get("β"));
            a.replaceAll(a,map.get("T"));
            a.replaceAll(a,map.get("D"));
            a.replaceAll(a,map.get("d"));
            a.replaceAll(a,map.get("e"));
            a.replaceAll(a,map.get("D"));
            a.replaceAll(a,map.get("Z"));
            a.replaceAll(a,map.get("μ"));
        }

        officeMath1.fromLatexMathCode(a);



        //保存文档
        String result = "D:/测试444.docx";
        doc.saveToFile(result, FileFormat.Docx_2013);
        System.out.println("ok");







    }
}
